// ==============================================================================================
// RibbonInfoPanel.cs
//
// Created by: NI, 2007.03.29
// Revised by: NI, 2007.11.23
// ==============================================================================================
using System;
using System.Drawing;
using System.Windows.Forms;

namespace RibbonExplorer.InfoPanel
{
  // ==============================================================================================
  /// <summary>
  /// This call represents the info panel of this application by wrapping around a panel.
  /// </summary>
  // ==============================================================================================
  public sealed class RibbonInfoPanel
  {
    #region Private fields

    private Panel _BasePanel;
    private UserControl _PanelControl;
    private static DefaultInfoPanel _DefaultPanel = new DefaultInfoPanel();

    #endregion

    #region Lifecycle methods

    // --------------------------------------------------------------------------------------------
    /// <summary>
    /// Creates an instance of this info panel based on the specified Windows Forms panel.
    /// </summary>
    /// <param name="basePanel">Base panel of this infop panel.</param>
    // --------------------------------------------------------------------------------------------
    public RibbonInfoPanel(Panel basePanel)
    {
      if (basePanel == null)
      {
        throw new ArgumentNullException("An existing panel must be used!");
      }
      _BasePanel = basePanel;
      PanelControl = _DefaultPanel;
    }

    #endregion

    #region Public properties

    // --------------------------------------------------------------------------------------------
    /// <summary>
    /// Gets the base panel behind this info panel.
    /// </summary>
    // --------------------------------------------------------------------------------------------
    public Panel BasePanel
    {
      get { return _BasePanel; }
    }

    // --------------------------------------------------------------------------------------------
    /// <summary>
    /// Gets the user control withis this info panel.
    /// </summary>
    // --------------------------------------------------------------------------------------------
    public UserControl PanelControl
    {
      get { return _PanelControl;  }
      set
      {
        if (_PanelControl != value)
        {
          //if (_PanelControl != null && _PanelControl != _DefaultPanel)
          //{
          //  _PanelControl.Dispose();
          //}
          _PanelControl = value;
          _BasePanel.Controls.Clear();
          UserControl toAttach = value;
          if (value == null)
          {
            toAttach = _DefaultPanel;
          }
          _BasePanel.Controls.Add(toAttach);
          toAttach.Dock = DockStyle.Fill;
        }
      }
    }

    #endregion

    #region DefaultInfoPanel class

    private class DefaultInfoPanel: UserControl
    {
      public DefaultInfoPanel()
      {
        BackColor = Color.LemonChiffon;
        Label defLabel = new Label();
        defLabel.Text = "Select a node from the tree.";
        defLabel.Dock = DockStyle.Fill;
        defLabel.TextAlign = ContentAlignment.MiddleCenter;
        Controls.Add(defLabel);
      }
    }

    #endregion
  }
}
